// 发送 get 请求
function requestGet(api) {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', api, false);
  xhr.send();
  return xhr.responseText;
}

// 测试 get 请求
console.log(requestGet('https://danjuanapp.com/djapi/fund/161725'));



// 发送 post 请求
function requestPost(api, params = {}) {
  const data = JSON.stringify(params);
  const xhr = new XMLHttpRequest();
  xhr.open('POST', api, false);
  xhr.setRequestHeader("Content-Type", "application/json");
  xhr.send(data);
  return xhr.responseText;
}

// 测试 post 请求
const params = {param:'this is a test'};
const api = 'https://foo.bar.com';
console.log(requestPost(api, params));